<template>
	<view class="content">
		<image :src="detail.picUrl" mode="widthFix" class="top-photo"></image>
		<view class="block detail-block">
			<!-- <view class="merchant-name">{{detail.ticketName}}</view> -->
			<view class="info-block">
				<view class="name-block">
					<view class="name">{{detail.ticketName}}</view>
					<view class="price">￥{{detail.ticketFare}}</view>
				</view>
				<view class="describe">{{detail.ticketDsc}}</view>
				<view class="label-block">
					<view v-for="(item,index) in detail.label" class="label-item">{{item}}</view>
				</view>
			</view>
			<view class="date-block">
				<view class="title">选择日期</view>
				<view v-for="(item,index) in date" :key="item.id" @click="dateActive=index"
					:class="dateActive==index?'active':''" class="date-item">
					<view class="date">{{item.date}}</view>
				</view>
			</view>
			<view class="number-block">
				<view class="label">预订数量</view>
				<view class="operation-block">
					<view @click="operationNum('-')" class="subtract-btn btn" :class="num==0?'disabled':''">
						<view class="iconfont icon-jianhao"></view>
					</view>
					<view class="num">{{num}}</view>
					<view @click="operationNum('+')" class="add-btn btn" :class="num==10?'disabled':''">
						<view class="iconfont icon-tianjia"></view>
					</view>
				</view>
			</view>
		</view>
		<view class="block instructions">
			<view class="title">预订须知</view>
			<view class="instructions-content">{{detail.buyRemind}}</view>
		</view>
		<view class="block settlement-block">
			<view class="total">
				合计：<view class="money">￥{{price}}</view>
			</view>
			<view class="btn1 btn" @click="reserve">立即预订</view>
		</view>
	</view>
</template>

<script>
	import {
		postReserve,
		getTickById
	} from '@/api/attractions.js';
	export default {
		data() {
			return {
				id: '',
				date: [],
				num: 0,
				detail: {
					photo: '/static/banner/banner1.jpg',
					merchantName: '酒泉天宝景区',
					name: '标准票',
					price: 103,
					label: ['当日可订', '有条件退改'],
					describe: '适用所有游客',
					content: '暂无',
				},
				dateActive: 0,
				price: 0,
			}
		},
		methods: {
			operationNum(operation) {
				if (operation == '-' && this.num != 0) {
					this.num--;
				}
				if (operation == '+' && this.num != 10) {
					this.num++;
				}
				this.price = this.detail.ticketFare * this.num;
			},
			//门票详情
			getTicketList() {
				let id = this.id
				getTickById({
					id
				}).then((res) => {
					if (res.code == 1) {
						console.log(res)
						if (res.data != null) {
							this.detail = res.data;
							console.log(this.detail)
							this.detail.label = res.data.ticketFeatureList
						}
					} else {
						console.log(res)
					}
				}).catch((res) => {
					console.log(res)
				})
			},
			//预定
			getList() {
				postReserve({
					orderType: 1,
					tid: this.id,
					sid: 0,
					hid: 0,
					count: this.num,
					price: this.price,
					useDate: this.date[this.dateActive].date
				}).then((res) => {
					if (res.code == 1) {
						console.log(res)
						uni.showToast({
							title: '预定成功',
							mask: true,
						})
					} else {
						uni.showToast({
							title: '加载失败',
							mask: true,
						})
					}
				}).catch((res) => {
					uni.hideLoading();
					uni.showToast({
						title: '加载失败',
						mask: true,
					})
				})
			},
			reserve() {
				this.getList()
			}
		},
		mounted() {
			let _this = this;
			let date = [];
			for (let i = 0; i < 4; i++) {
				let res = _this.utils.getCurrentTime('d', '-', i);
				res = res.slice(5);
				let text = ''
				switch (i) {
					case 0:
						text = '今天';
						break;
					case 1:
						text = '明天';
						break;
					case 2:
						text = '后天';
						break;
					case 3:
						text = '';
						break;
				}
				date.push({
					date: res,
					name: text,
				})
			}
			this.date = date;
		},
		onLoad(e) {
			console.log(e)
			this.id = e.id
			this.getTicketList()
		},
	}
</script>

<style lang="scss">
	.content {
		min-height: 100vh;
		background: #f4f4f4;
		display: flex;
		flex-direction: column;
		padding-bottom: 130rpx;

		.top-photo {
			width: 100%;
			height: auto;
		}

		.block.detail-block {
			width: 100%;
			display: flex;
			flex-direction: column;
			background: #fff;
			border-radius: 20rpx 20rpx 0 0;
			margin-top: -60rpx;
			position: relative;
			padding: 40rpx;
			padding-bottom: 0;

			.merchant-name {
				font-size: 36rpx;
			}

			.info-block {
				margin-top: 20rpx;
				display: flex;
				flex-direction: column;
				padding: 20rpx 0;
				border-bottom: 1px solid #efefef;

				.name-block {
					display: flex;
					flex-direction: row;
					align-items: center;

					.name {
						flex-grow: 1;
						font-size: 42rpx;
						font-weight: bold;
						color: $color-primary-text;
					}

					.price {
						font-size: 42rpx;
						color: $color-danger;
					}
				}

				.describe {
					display: flex;
					color: $color-secondary-text;
					font-size: 28rpx;
					margin-top: 20rpx;
				}

				.label-block {
					display: flex;
					flex-direction: row;
					flex-wrap: wrap;
					margin-top: 20rpx;

					.label-item {
						font-size: 24rpx;
						color: $color-primary;
						background: rgba(64, 158, 255, .1);
						padding: 6rpx 8rpx;
						margin-right: 10rpx;
						border-radius: 6rpx;
						margin-bottom: 10rpx;
					}
				}
			}

			.date-block {
				padding: 30rpx 0;
				display: flex;
				flex-direction: row;
				flex-wrap: wrap;
				position: relative;
				border-bottom: 1px solid #efefef;

				.title {
					width: 100%;
					font-size: 34rpx;
					font-weight: bold;
					margin-bottom: 30rpx;
				}

				.date-item {
					flex-grow: 1;
					display: flex;
					flex-direction: row;
					align-items: center;
					justify-content: center;
					background: #fff;
					padding: 20rpx 0;
					margin: 0 10rpx;
					border: 1px solid #efefef;
					border-radius: 50rpx;

					.date {
						font-weight: bold;
						font-size: 28rpx;
						margin-right: 10rpx;
					}

					.date.more {
						font-weight: normal;
					}
				}

				.date-item.active {
					border: 1px solid $color-primary;
					background: $color-primary;
					color: #fff;
				}
			}

			.number-block {
				display: flex;
				flex-direction: row;
				align-items: center;
				height: 120rpx;

				.label {
					flex-grow: 1;
					font-size: 34rpx;
					font-weight: bold;
				}

				.operation-block {
					flex-grow: 0;
					display: flex;
					flex-direction: row;
					align-items: center;

					.num {
						margin: 0 20rpx;
					}

					.btn {
						display: flex;
						align-items: center;
						justify-content: center;
						font-size: 28rpx;
						border-radius: 50%;
						width: 50rpx;
						height: 50rpx;
						background: $color-primary;
						color: #fff;
					}

					.btn.disabled {
						background: #efefef;
						color: $color-secondary-text;
					}
				}
			}
		}

		.block.instructions {
			margin-top: 30rpx;
			background: #fff;
			padding: 30rpx;
			display: flex;
			flex-direction: column;

			.title {
				font-size: 34rpx;
				font-weight: bold;
				margin-bottom: 20rpx;
			}

			.instructions {
				font-size: 28rpx;
			}
		}

		.block.settlement-block {
			position: fixed;
			bottom: 0;
			left: 0;
			width: 100%;
			height: 110rpx;
			display: flex;
			flex-direction: row;
			align-items: center;
			background: #fff;
			padding: 0 30rpx;
			box-shadow: 0 -2px 15px 0px rgba(0, 0, 0, 0.08);

			.total {
				display: flex;
				flex-direction: row;
				flex-grow: 1;

				.money {
					color: $color-danger;
				}
			}

			.btn {
				flex-grow: 0;
				width: 240rpx;
				height: 70rpx;
			}
		}
	}
</style>
